[PATCH] Search for the bitcode libraries in a multiarch directory
authorCordell Bloor <cgmb@slerp.xyz>
Wed, 8 Mar 2023 09:57:51 +0000 (02:57 -0700)
committerGianfranco Costamagna <locutusofborg@debian.org>
Thu, 7 Sep 2023 22:43:45 +0000 (00:43 +0200)
The Debian path for the rocm-device-libs is
/usr/lib/$(DEB_HOST_MULTIARCH)/amdgcn/bitcode

Forwarded: not-needed

Gbp-Pq: Topic amdgpu
Gbp-Pq: Name bitcode-multiarch.patch

clang/lib/Driver/ToolChains/AMDGPU.cpp

index fc47d7f1994404e8fe264dd7c8e36b93072b2255..2e8e56b39ff60c57e66969b4d59710a9116bc1f1 100644 (file)
@@ -14,6 +14,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/Triple.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/FileUtilities.h"
@@ -423,16 +424,21 @@ void RocmInstallationDetector::detectDeviceLibrary() {
     // The possible structures are:
     // - ${ROCM_ROOT}/amdgcn/bitcode/*
     // - ${ROCM_ROOT}/lib/*
+    // - ${ROCM_ROOT}/lib/<multiarch>/amdgcn/bitcode/*
     // - ${ROCM_ROOT}/lib/bitcode/*
-    // so try to detect these layouts.
-    static constexpr std::array<const char *, 2> SubDirsList[] = {
-        {"amdgcn", "bitcode"},
-        {"lib", ""},
-        {"lib", "bitcode"},
+    // so try to detect these layouts. Note that bitcode is associated with the
+    // compiler that built it (not the target architecture).
+    llvm::Triple HostTriple(llvm::sys::getProcessTriple());
+    std::string Multiarch = Twine(HostTriple.getArchName() + "-linux-gnu").str();
+    static const std::array<std::string, 4> SubDirsList[] = {
+        {"amdgcn", "bitcode", "", ""},
+        {"lib", "", "", ""},
+        {"lib", Multiarch, "amdgcn", "bitcode"},
+        {"lib", "bitcode", "", ""},
     };
 
     // Make a path by appending sub-directories to InstallPath.
-    auto MakePath = [&](const llvm::ArrayRef<const char *> &SubDirs) {
+    auto MakePath = [&](const llvm::ArrayRef<std::string> &SubDirs) {
       auto Path = CandidatePath;
       for (auto SubDir : SubDirs)
         llvm::sys::path::append(Path, SubDir);